<template>
  <div class=''>
    
  </div>
</template>
<script setup>

import { useWebSocket } from "@vueuse/core";

import {watch, onMounted, ref} from "vue"
import { useEarthStore } from "@/stores/earth";

let earthStore = useEarthStore()

const { status, data, send, open, close } = useWebSocket(wsurl, {
  autoReconnect: true,
});

let globalmessage = ''
let message1 = ref('')

onMounted(() => {
  
})



watch(data, function (n, o) {

  console.log(data);

  
  try {
    let resitem = JSON.parse(n);
    earthStore.taskws.data = resitem
    console.log(resitem);
    // jiankongitems.map(item => {
    //   if (item.distributeId == resitem.batchId) {
    //     dataList.value[item.iindex].status = resitem.processInfo;
    //   }
    //   if (resitem.processInfo.indexOf("完成") != -1) {
    //     loadData();
    //   }
    // });
    // ElNotification.success({
    //   title: '任务执行中',
    //   message: `11111`,
    //   showClose: false,
    //   duration: 0
    // })

    if ( resitem.data.type == '任务项处理完成' ) {
      let mmm = `
          任务路径：${resitem.data.dirpath}<br/>
          任务进度：${resitem.data.jindu}<br/>
          当前处理路径：${resitem.data.name}<br/>
          当前处理耗时${resitem.data.haoshi / 1000}s<br/>
        `
      if (globalmessage == '') {
        globalmessage = ElNotification.success({
          title: '任务执行中',
          message: mmm,
          showClose: false,
          dangerouslyUseHTMLString: true,
          position: 'bottom-left',
          duration: 0
        })
      }else{
        globalmessage.close()
        globalmessage = ElNotification.success({
          title: '任务执行中',
          message: mmm,
          showClose: false,
          dangerouslyUseHTMLString: true,
          position: 'bottom-left',
          duration: 0
        })
      }

    }else{
      setTimeout(() => {
        if (globalmessage != '') {
          globalmessage.close()
          globalmessage = ''
        }
      }, 3000);
    }

    

  } catch (error) {

  }
});


</script>
<style lang='scss' scoped>
</style>